<?php

/**
 * Input Plugin
 * @author ReGeDa
 */
class Input extends Plugin_Object {

	/**
	 * Constructor
	 */
	public function __construct() {
		parent::__construct();
	}

	/**
	 * Get persistant plugin state
	 * @override
	 * @return boolean
	 */
	public function is_persistant() {
		return TRUE;
	}

	/**
	 * XSS cleaner a value
	 * @param string $val 
	 */
	public function xss_clean(&$val) {
		$val = &platcode()->plugins->import('XSS')->set_source($val)->filter();
	}

	/**
	 * Get input value
	 * @param array $data
	 * @param string $index
	 * @param boolean $xss_clean
	 * @return mixed
	 */
	private function &get_input_value(&$data, $index, $xss_clean) {
		if (isset($data[$index])) {

			// must be clean
			if ($xss_clean)
				$this->xss_clean($data[$index]);

			// result
			return $data[$index];
		}
		return NULL;
	}

	/**
	 * Fetch $_GET value
	 * @param string $index
	 * @param boolean $xss_clean
	 * @return mixed
	 */
	public function &get($index, $xss_clean = FALSE) {
		return $this->get_input_value($_GET, $index, $xss_clean);
	}

	/**
	 * Fetch $_POST value
	 * @param string $index
	 * @param boolean $xss_clean
	 * @return mixed
	 */
	public function &post($index, $xss_clean = FALSE) {
		return $this->get_input_value($_POST, $index, $xss_clean);
	}

	/**
	 * Fetch $_COOKIE value
	 * @param string $index
	 * @param boolean $xss_clean
	 * @return mixed
	 */
	public function &cookie($index, $xss_clean = FALSE) {
		return $this->get_input_value($_COOKIE, $index, $xss_clean);
	}


}

// end of file